package demo2;

import java.util.*;

class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();

        for(int i = 0; i<tokens.length; i++) {
            String s = tokens[i];
            if(s.equals("+")) {
                int b = stack.pop();
                int a = stack.pop();
                stack.add(a+b);
            }else if(s.equals("-")) {
                int b = stack.pop();
                int a = stack.pop();
                stack.add(a-b);
            }else if(s.equals("*")) {
                int b = stack.pop();
                int a = stack.pop();
                stack.add(a*b);
            }else if(s.equals("/")) {
                int b = stack.pop();
                int a = stack.pop();
                stack.add(a/b);
            }else {
                int x = Integer.parseInt(s);
                stack.add(x);
            }
        }
        return stack.pop();
    }
}



class Solution1 {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(String x:tokens) {
            if(!isOperation(x)) {
                //是数字
                stack.push(Integer.parseInt(x));
            }else {
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch(x) {
                    case "+":
                        stack.push(num1+num2);
                        break;

                    case "-":
                        stack.push(num1-num2);
                        break;

                    case "*":
                        stack.push(num1*num2);
                        break;

                    case "/":
                        stack.push(num1/num2);
                        break;
                }
            }
        }
        return stack.pop();
    }
    private boolean isOperation(String s) {
        if(s.equals("+")||s.equals("-")||s.equals("*")||s.equals("/")){
            return true;
        }
        return false;
    }
}


public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()) {
            int n = scanner.nextInt();
            Stack<Integer> stack = new Stack<>();

            for(int i = 0; i<n; i++) {
                String s = scanner.next();
                if(s.equals("+")) {
                    int b = stack.pop();
                    int a = stack.pop();
                    stack.add(a+b);
                }else if(s.equals("-")) {
                    int b = stack.pop();
                    int a = stack.pop();
                    stack.add(a-b);
                }else if(s.equals("*")) {
                    int b = stack.pop();
                    int a = stack.pop();
                    stack.add(a*b);
                }else if(s.equals("/")) {
                    int b = stack.pop();
                    int a = stack.pop();
                    stack.add(a/b);
                }else {
                    int x = Integer.parseInt(s);
                    stack.add(x);
                }
            }
            System.out.println(stack.pop());
        }
    }
}

/*
3
2 3 +
5
2 2 + 3 *
5
2 2 3 + *
 */
